package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelListLogic {
	return &NovelListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 小说列表
func (l *NovelListLogic) NovelList(in *user.NovelListRequest) (*user.NovelListResponse, error) {
	// todo: add your logic here and delete this line
	var novels []models.Novels
	models.DB.Order("hot desc").Find(&novels)
	var novellisst []*user.NovelList
	for _, novel := range novels {
		list := user.NovelList{
			Title:  novel.Title,
			Writer: novel.Writer,
			Hot:    novel.Hot,
			Image:  novel.Image,
			Price:  float32(novel.Price),
			Num:    novel.Num,
		}
		novellisst = append(novellisst, &list)
	}

	return &user.NovelListResponse{
		List: novellisst,
	}, nil
}
